from collections import Counter
from typing import List


class Solution:
    def minimumSwitchingTimes(self, source: List[List[int]], target: List[List[int]]) -> int:
        m, n = len(source), len(source[0])

        color = Counter()
        for i in range(m):
            for j in range(n):
                color[source[i][j]] += 1
                color[target[i][j]] -= 1

        return sum(color[k] for k in color if color[k] > 0)


if __name__ == "__main__":
    print(Solution().minimumSwitchingTimes(source=[[1, 3], [5, 4]], target=[[3, 1], [6, 5]]))  # 1
    print(Solution().minimumSwitchingTimes(source=[[1, 2, 3], [3, 4, 5]], target=[[1, 3, 5], [2, 3, 4]]))  # 0
